﻿using System;
using System.Data;
using System.Data.OracleClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class UDesktop : UserPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Head1.Title = "欢迎登录" + ConfigurationManager.AppSettings["SystemName"];
            Sysword.InnerText = ConfigurationManager.AppSettings["SystemName"];
            Menu_DataBind();
        }
    }

    protected void LBlogout_Click(object sender, EventArgs e)
    {
        if (Session["LoginUser"] != null)
        {
            log4net.LogManager.GetLogger(GetType()).Info("{ClientIP:'" + Tools.GetClientIP() + "',Msg:'"
                + Session["LoginUser"].ToString() + " logout.'}");
        }
        Session["LoginUser"] = null;
        Response.Redirect("~/ULogin.aspx");
    }

    private void Menu_DataBind()
    {
        string sqlstr = @"SELECT DISTINCT c.data_name AS page_url,c.data_code AS page_title,c.order_num
                          FROM u_user_role_t a
                         INNER JOIN (SELECT data_code,data_name FROM u_pub_data_t 
                                            WHERE data_type='role_list' AND if_valid = 'Y') d
                              ON a.role_code = d.data_code
                         INNER JOIN u_role_page_t b
                              ON a.role_code = b.role_code
                             AND b.if_valid = 'Y'
                         INNER JOIN (SELECT data_code,data_name,order_num FROM u_pub_data_t 
                                            WHERE data_type='menu_page' AND if_valid = 'Y') c
                              ON c.data_code = b.page_code
                         WHERE login_name = :login_name
                             AND a.if_valid = 'Y'
                         ORDER BY c.order_num";
        OracleParameter[] _params = {
            new OracleParameter(":login_name",OracleType.VarChar,16)
        };
        _params[0].Value = Session["LoginUser"].ToString();
        UMenuList.DataSource = OracleHelper.ExecuteDataSet(sqlstr, CommandType.Text, _params);
        UMenuList.DataBind();
    }
}
